//
//  MBProgressHUD+ZUtilities.m
//  WeClubs
//
//  Created by Zed Link on 9/4/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "MBProgressHUD+ZUtilities.h"

@implementation MBProgressHUD (ZUtilities)

+ (MBProgressHUD *)zAlertMessage:(NSString *)message to:(UIView *)view performBlock:(void(^)())todoBlock
{
    MBProgressHUD *hud = [self zAlertToastMessage:message];
    hud.completionBlock = todoBlock;
    
    return hud;
}

+ (MBProgressHUD *)zAlertToastMessage:(NSString *)message
{
    return [self zAlertMessage:message to:KEY_WINDOW afterDelay:GENERAL_ALERT_DURATION];
}

+ (MBProgressHUD *)zAlertMessage:(NSString *)message to:(UIView *)view afterDelay:(NSTimeInterval)delay
{
    MBProgressHUD *hud = [self zAlertConfirmMessage:message to:view];
    [hud hideAnimated:YES afterDelay:delay];
    
    return hud;
}

+ (MBProgressHUD *)zAlertProgress:(NSString *)message
{
    return [self zAlertProgressMessage:message to:KEY_WINDOW];
}

//+ (MBProgressHUD *)zAlertConfirmMessage:(NSString *)message to:(UIView *)view andAddTarget:(id)target action:(SEL)selector
//{
//    MBProgressHUD *hud = [self zAlertConfirmMessage:message to:view];
//    
//    [hud.button setTitle:@"确定" forState:UIControlStateNormal];
//    [hud.button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
//    
//    return hud;
//}

#pragma mark - Private Method

+ (MBProgressHUD *)zAlertConfirmMessage:(NSString *)message to:(UIView *)view
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = message;
    
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:0.2f];

    return hud;
}

+ (MBProgressHUD *)zAlertProgressMessage:(NSString *)message to:(UIView *)view
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = message;
    
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:0.2f];
    
    return hud;
}

@end
